
// <copyright file="ConnectionPool.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The connection pool.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Tests.Pooling
{
    using SubhadraSolutions.Sharp.Utils.Pooling;

    /// <summary>
    /// The connection pool.
    /// </summary>
    public class ConnectionPool : AbstractPool<DummyConnection, DummyConnectionWrapper>
    {
        #region Public Methods and Operators

        /// <summary>
        /// The get connection.
        /// </summary>
        /// <param name="connectionString">
        /// The connection string.
        /// </param>
        /// <returns>
        /// The <see cref="IConnection"/>.
        /// </returns>
        public IConnection GetConnection(string connectionString)
        {
            return this.getObject(delegate(DummyConnection adaptedObject, bool isNewlyCreatedAdaptedObject, object tag)
                {
                    if (isNewlyCreatedAdaptedObject)
                    {
                        adaptedObject.ConnectionString = connectionString;
                        return true;
                    }

                    return adaptedObject.ConnectionString == connectionString;
                }, null);
        }

        #endregion Public Methods and Operators

        #region Methods

        /// <summary>
        /// The get adaptedObject.
        /// </summary>
        /// <returns>
        /// The <see cref="DummyConnection"/>.
        /// </returns>
        protected override DummyConnection getAdaptedObject()
        {
            return new DummyConnection();
        }

        #endregion Methods
    }
}
